package com.daoyin.ssph.dao;

import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.daoyin.ssph.bean.Translation;

/**
 * A data access object (DAO) providing persistence and search support for
 * Translation entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.daoyin.ssph.bean.Translation
 * @author MyEclipse Persistence Tools
 */

public class TranslationDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(TranslationDAO.class);
	// property constants
	public static final String TITLE = "title";
	public static final String TYPE = "type";
	public static final String NATURE = "nature";
	public static final String SCOPE = "scope";
	public static final String ADRESS = "adress";
	public static final String DEMAND = "demand";
	public static final String DUTY = "duty";
	public static final String NUMBER = "number";
	public static final String TIME = "time";
	public static final String DEADTIME = "deadtime";
	public static final String PUBLISH = "publish";

	protected void initDao() {
		// do nothing
	}

	public void save(Translation transientInstance) {
		log.debug("saving Translation instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Translation persistentInstance) {
		log.debug("deleting Translation instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Translation findById(java.lang.Integer id) {
		log.debug("getting Translation instance with id: " + id);
		try {
			Translation instance = (Translation) getHibernateTemplate().get(
					"com.daoyin.ssph.bean.Translation", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Translation instance) {
		log.debug("finding Translation instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Translation instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Translation as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByTitle(Object title) {
		return findByProperty(TITLE, title);
	}

	public List findByType(Object type) {
		return findByProperty(TYPE, type);
	}

	public List findByNature(Object nature) {
		return findByProperty(NATURE, nature);
	}

	public List findByScope(Object scope) {
		return findByProperty(SCOPE, scope);
	}

	public List findByAdress(Object adress) {
		return findByProperty(ADRESS, adress);
	}

	public List findByDemand(Object demand) {
		return findByProperty(DEMAND, demand);
	}

	public List findByDuty(Object duty) {
		return findByProperty(DUTY, duty);
	}

	public List findByNumber(Object number) {
		return findByProperty(NUMBER, number);
	}

	public List findByTime(Object time) {
		return findByProperty(TIME, time);
	}

	public List findByDeadtime(Object deadtime) {
		return findByProperty(DEADTIME, deadtime);
	}

	public List findByPublish(Object publish) {
		return findByProperty(PUBLISH, publish);
	}

	public List findAll() {
		log.debug("finding all Translation instances");
		try {
			String queryString = "from Translation order by time desc";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Translation merge(Translation detachedInstance) {
		log.debug("merging Translation instance");
		try {
			Translation result = (Translation) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Translation instance) {
		log.debug("attaching dirty Translation instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Translation instance) {
		log.debug("attaching clean Translation instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static TranslationDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (TranslationDAO) ctx.getBean("TranslationDAO");
	}
}